package com.lanou.moving.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lanou.moving.R;
import com.lanou.moving.entity.SearchAlbumRoot;

import java.util.List;

import it.sephiroth.android.library.picasso.Picasso;

/**
 * Created by dllo on 15/10/24.
 */
public class SearchAlbumAdapter extends BaseAdapter {
    private Context mcontext;
    private List<SearchAlbumRoot.DataEntity> data;
    private SearchAlbumRoot.DataEntity entity;


    public SearchAlbumAdapter(Context context, List<SearchAlbumRoot.DataEntity> datas) {
        mcontext = context;
        data = datas;


    }

    @Override
    public int getCount() {
        return data != null && data.size() > 0 ? data.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return data!=null&&data.size()>0?data.get(position):null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder=null;
        if (convertView==null){
            convertView= LayoutInflater.from(mcontext).inflate(R.layout.search_album_content,null);
            holder=new ViewHolder();
            holder.album_img= (ImageView) convertView.findViewById(R.id.album_img);
            holder.album_name= (TextView) convertView.findViewById(R.id.album_name);
            holder.album_singer_name= (TextView) convertView.findViewById(R.id.album_singer_name);
            holder.pushing_time= (TextView) convertView.findViewById(R.id.pushing_time);
            convertView.setTag(holder);

        }else {
            holder= (ViewHolder) convertView.getTag();
        }
        entity=(SearchAlbumRoot.DataEntity)getItem(position);
        if (entity!=null){
            holder.pushing_time.setText(entity.getPublishDate());
            holder.album_name.setText(entity.getName());
            holder.album_singer_name.setText(entity.getSingerName());
            Picasso.with(mcontext).load(entity.getPicUrl()).into(holder.album_img);
            holder.album_img.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {

                }
            });
        }
        return convertView;
    }

    private class  ViewHolder{
        private ImageView album_img;
        private TextView album_name,album_singer_name,pushing_time;
    }

}
